package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 复制文件，块读写
 */
public class CopyDemo2 {
    public static void main(String[] args) throws IOException {


        /*FileInputStream fis = new FileInputStream("picture.jpg");
        FileOutputStream fos = new FileOutputStream("picture_cy2.jpg");
        long startTime = System.currentTimeMillis();

        int d;
        byte[] data = new byte[1024*10];

        while((d=fis.read(data))!=-1){
            fos.write(data);
            //fos.write(data,0,d);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("读取完毕，耗时："+(endTime-startTime)+"ms");
        fis.close();
        fos.close();*/
        FileInputStream fis = new FileInputStream("./picture.jpg");
        FileOutputStream fos = new FileOutputStream("./picture_cy2.jpg");
        long startTime = System.currentTimeMillis();
        int flag;
        byte[] data = new byte[1024*10];
        while((flag=fis.read(data))!=-1){
            fos.write(data);
        }

        long endTime = System.currentTimeMillis();
        System.out.println("复制完毕，耗时："+(endTime-startTime)+"ms");
        fis.close();
        fos.close();
    }
}
